<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>微信小程序 | mozihao</title><meta name="keywords" content="微信小程序"><meta name="author" content="mozihao"><meta name="copyright" content="mozihao"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="页面的生命周期onLoad—-监听页面的加载 onReady—监听页面初次渲染完成 onShow—监听页面显示 onHide—监听页面隐藏 onUnload—监听页面卸载 组件的生命周期created组件实例化，但节点树还未导出，因此这时不能用setData attached节点完成，可以用setData渲染节点，但无法操作节点 ready组件布局完成，这时可以获取节点信息，也可以操作节点 mov">
<meta property="og:type" content="article">
<meta property="og:title" content="微信小程序">
<meta property="og:url" content="https://mo_zi_hao.gitee.io/blog/posts/35506/index.html">
<meta property="og:site_name" content="mozihao">
<meta property="og:description" content="页面的生命周期onLoad—-监听页面的加载 onReady—监听页面初次渲染完成 onShow—监听页面显示 onHide—监听页面隐藏 onUnload—监听页面卸载 组件的生命周期created组件实例化，但节点树还未导出，因此这时不能用setData attached节点完成，可以用setData渲染节点，但无法操作节点 ready组件布局完成，这时可以获取节点信息，也可以操作节点 mov">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/1234.jpg">
<meta property="article:published_time" content="2021-08-29T15:22:14.600Z">
<meta property="article:modified_time" content="2021-08-29T15:22:14.601Z">
<meta property="article:author" content="mozihao">
<meta property="article:tag" content="微信小程序">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/1234.jpg"><link rel="shortcut icon" href="/blog/img/favicon.png"><link rel="canonical" href="https://mo_zi_hao.gitee.io/blog/posts/35506/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/blog/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/blog/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-08-29 23:22:14'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    })(window)</script><link rel="stylesheet" type="text/css" href="./css/iconfont.css" media="all"><meta name="generator" content="Hexo 5.4.2"><link rel="alternate" href="/blog/atom.xml" title="mozihao" type="application/atom+xml">
</head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC008.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">24</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">16</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 前端知识思维导图</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gitee.com/mo_zi_hao/picsBed/raw/master/image/1234.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/blog/">mozihao</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/blog/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/blog/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/blog/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/blog/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/blog/about/"><i class="fa-fw fas fa-heart"></i><span> 前端知识思维导图</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">微信小程序</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-08-29T15:22:14.600Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-08-29T15:22:14.601Z" title="更新于 2021-08-29 23:22:14">2021-08-29</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/blog/categories/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/">微信小程序</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.9k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>20分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="微信小程序"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="页面的生命周期"><a href="#页面的生命周期" class="headerlink" title="页面的生命周期"></a>页面的生命周期</h3><p>onLoad—-监听页面的加载</p>
<p>onReady—监听页面初次渲染完成</p>
<p>onShow—监听页面显示</p>
<p>onHide—监听页面隐藏</p>
<p>onUnload—监听页面卸载</p>
<h3 id="组件的生命周期"><a href="#组件的生命周期" class="headerlink" title="组件的生命周期"></a>组件的生命周期</h3><p>created组件实例化，但节点树还未导出，因此这时不能用setData</p>
<p>attached节点完成，可以用setData渲染节点，但无法操作节点</p>
<p>ready组件布局完成，这时可以获取节点信息，也可以操作节点</p>
<p>moved组件实例被转移到树的另一个位置</p>
<p>detached组件实例从节点树中移除</p>
<p>小程序中只有组件才有methods，在page里的方法全写在onload中。都有data</p>
<p><strong>注意：page中再page外部定义的静态变量，如果应用在data里面，静态变量只会初始化一次，而且data的初始化也只是初始化一次，如果静态变量发生改变data里面的值不会跟着改变，而且，如果定义的那个静态变量是一个动态的值，当第二次这个页面的时候，当动态的值改变了，那个静态变量也是不会跟着改变的，因为它只初始化一次</strong></p>
<h3 id="hidden控制组件不生效"><a href="#hidden控制组件不生效" class="headerlink" title="hidden控制组件不生效"></a>hidden控制组件不生效</h3><p>hidden控制组件不生效，wx:if可以，如果要使用hidden隐藏组件，需要在组件再嵌套一层在外层使用hidden</p>
<h3 id="navigateTo"><a href="#navigateTo" class="headerlink" title="navigateTo"></a>navigateTo</h3><p><strong>navigateTo跳转页面会把传过去的数据默认转成字符串–需要手动转换数据格式</strong></p>
<p><strong>使用wx:navigateTo 这个api的时候，注意？号后面的第一个参数如果过长，可能后面的带参丢失的情况</strong></p>
<p>这种路径参数传递前先编下码，使用encodeURIComponent先编码，之后使decodeURIComponent</p>
<p>解码</p>
<h3 id="带参传值获取属性值"><a href="#带参传值获取属性值" class="headerlink" title="带参传值获取属性值"></a>带参传值获取属性值</h3><p>一般绑定的bindchange事件的传值和input组件的value值都是使用e.detail.value</p>
<p>使用自定义属性传值data-index = “1”（在标签中绑定）使用e.currentTarget.dataset[‘index’]</p>
<p>通过跳转传值value的，需要在onLoad周期函数 options.value</p>
<h3 id="父子组件之间的传值"><a href="#父子组件之间的传值" class="headerlink" title="父子组件之间的传值"></a>父子组件之间的传值</h3><h4 id="父传子"><a href="#父传子" class="headerlink" title="父传子"></a>父传子</h4><p>在父组件中 :</p>
<p>绑定子组件current=</p>
<p>绑定子组件dataLogs=</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">main</span> <span class="attr">dataLogs</span>=<span class="string">&quot;&#123;&#123;logs&#125;&#125;&quot;</span> <span class="attr">current</span>=<span class="string">&quot;&#123;&#123;current&#125;&#125;&quot;</span> <span class="attr">bind:myevent</span>=<span class="string">&quot;onMyevent&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">main</span>&gt;</span></span><br></pre></td></tr></table></figure>



<p>子组件中:</p>
<p>在properties中定义父组件传过来的变量current dataLogs ，其中observers为观察当前变量变化时出发方法</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">Component(&#123;</span><br><span class="line">  properties: &#123;</span><br><span class="line">    <span class="comment">// 这里定义了innerText属性，属性值可以在组件使用时指定</span></span><br><span class="line">    dataLogs: &#123;</span><br><span class="line">      type: <span class="built_in">Array</span>,</span><br><span class="line">      value: [],</span><br><span class="line">    &#125;,</span><br><span class="line">    current: &#123;</span><br><span class="line">      type: <span class="built_in">Number</span>,</span><br><span class="line">      value:<span class="number">0</span>,</span><br><span class="line">      observers:<span class="function"><span class="keyword">function</span>(<span class="params">newval,oldval,</span>)</span>&#123;</span><br><span class="line">        <span class="built_in">console</span>.log(newval + <span class="string">&quot;current&quot;</span>)</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  data: &#123;</span><br><span class="line">  &#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line">&#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h4 id="子传父"><a href="#子传父" class="headerlink" title="子传父"></a>子传父</h4><p><strong>在父组件中</strong> :</p>
<p>使用bind：子组件自定义方法myevent=”当前组件中的方法onMyevent”</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">main</span> <span class="attr">dataLogs</span>=<span class="string">&quot;&#123;&#123;logs&#125;&#125;&quot;</span> <span class="attr">current</span>=<span class="string">&quot;&#123;&#123;current&#125;&#125;&quot;</span> <span class="attr">bind:myevent</span>=<span class="string">&quot;onMyevent&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">main</span>&gt;</span></span><br></pre></td></tr></table></figure>



<p>调用子组件传过来的参数使用，e.detail.子组件传的参数名</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">Page(&#123;</span><br><span class="line">  data: &#123;</span><br><span class="line">    current: <span class="number">0</span>,</span><br><span class="line">    logs: []</span><br><span class="line">  &#125;,</span><br><span class="line">  onLoad: <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">  onMyevent:<span class="function"><span class="keyword">function</span>(<span class="params">e</span>)</span>&#123;</span><br><span class="line">    <span class="built_in">this</span>.setData(&#123;</span><br><span class="line">      current:e.detail.current</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<p><strong>子组件中</strong> :</p>
<p>子组件中的change方法，调用this.triggerEvent(上面在子组件自定义方法myevent，{参数名:当前组件的变量})</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">Component(&#123;</span><br><span class="line">  properties: &#123;</span><br><span class="line">  &#125;,</span><br><span class="line">  data: &#123;</span><br><span class="line">    swiper_current: <span class="number">0</span>,</span><br><span class="line">  &#125;,</span><br><span class="line"> </span><br><span class="line">  methods: &#123;</span><br><span class="line">    onSlideChangeEnd:<span class="function"><span class="keyword">function</span>(<span class="params">e</span>)</span>&#123;</span><br><span class="line">      <span class="built_in">this</span>.setData(&#123;</span><br><span class="line">        swiper_current: e.detail.current</span><br><span class="line">      &#125;)</span><br><span class="line">      <span class="built_in">this</span>.change()</span><br><span class="line">      <span class="comment">// console.log(this.data.swiper_current)</span></span><br><span class="line">    &#125;,</span><br><span class="line">    change:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">      <span class="built_in">this</span>.triggerEvent(<span class="string">&#x27;myevent&#x27;</span>, &#123; <span class="attr">current</span>: <span class="built_in">this</span>.data.swiper_current&#125;);</span><br><span class="line">    &#125;,</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h3 id="向绑定的方法传参"><a href="#向绑定的方法传参" class="headerlink" title="向绑定的方法传参"></a>向绑定的方法传参</h3><p>当前页面</p>
<p>标签中自定义   data-变量名=   向getDetail方法传参</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;imgUrl&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;index&quot;</span> <span class="attr">bindtap</span>=<span class="string">&quot;getDetail&quot;</span> <span class="attr">data-item</span>=<span class="string">&quot;&#123;&#123;item&#125;&#125;&quot;</span> <span class="attr">data-index</span>=<span class="string">&quot;&#123;&#123;index&#125;&#125;&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">text</span>&gt;</span>第&#123;&#123;index&#125;&#125;<span class="tag">&lt;/<span class="name">text</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">image</span> <span class="attr">class</span>=<span class="string">&quot;img-style&quot;</span> <span class="attr">src</span>=<span class="string">&quot;&#123;&#123;item&#125;&#125;&quot;</span> <span class="attr">mode</span>=<span class="string">&quot;&quot;</span> &gt;</span><span class="tag">&lt;/<span class="name">image</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure>



<h4 id="获取自定义变量–参数"><a href="#获取自定义变量–参数" class="headerlink" title="获取自定义变量–参数:"></a><strong>获取自定义变量–参数</strong>:</h4><p>getDetail方法中 e.currentTager.dataset[“参数名”]</p>
<h4 id="页面跳转-传参（wx-navgateTo不能跳转到tabber页面）"><a href="#页面跳转-传参（wx-navgateTo不能跳转到tabber页面）" class="headerlink" title="页面跳转+传参（wx.navgateTo不能跳转到tabber页面）:"></a><strong>页面跳转+传参（wx.navgateTo不能跳转到tabber页面）</strong>:</h4><p>传参:  路径后面 + ?data（变量名）= value</p>
<h5 id="为避免带参的参数中存在-？-会出现参数丢失的情况"><a href="#为避免带参的参数中存在-？-会出现参数丢失的情况" class="headerlink" title="为避免带参的参数中存在 ？ ,会出现参数丢失的情况:"></a><strong>为避免带参的参数中存在 ？ ,会出现参数丢失的情况</strong>:</h5><p><strong>解决方案：</strong>这种路径参数传递前先编下码，使用encodeURIComponent先编码，之后使decodeURIComponent解码，否则会出现丢字的情况例 如：”&amp;”后面的字会丢失</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Component(&#123;</span><br><span class="line">  properties: &#123;</span><br><span class="line">  &#125;,</span><br><span class="line">  data: &#123;</span><br><span class="line">    imgUrl:[],</span><br><span class="line">  &#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line">    <span class="comment">// 这里是一个自定义方法</span></span><br><span class="line">    customMethod: <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;&#125;,</span><br><span class="line">    <span class="function"><span class="title">getDetail</span>(<span class="params">e</span>)</span>&#123;</span><br><span class="line">      <span class="built_in">console</span>.log(e.currentTarget.dataset[<span class="string">&#x27;index&#x27;</span>])</span><br><span class="line">      wx.navigateTo(&#123;</span><br><span class="line">      url: <span class="string">`../../pages/pages/page<span class="subst">$&#123;e.currentTarget.dataset[<span class="string">&#x27;index&#x27;</span>]+<span class="number">1</span>&#125;</span>/index?data=<span class="subst">$&#123;e.currentTarget.dataset[<span class="string">&#x27;item&#x27;</span>]&#125;</span>`</span></span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<p><strong>目标页面</strong></p>
<p>跳转到目标页面中使用在options参数中获取 options.data</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">onLoad: <span class="function"><span class="keyword">function</span> (<span class="params">options</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">console</span>.log(options)</span><br><span class="line">    <span class="built_in">this</span>.setData(&#123;</span><br><span class="line">      url:options.data</span><br><span class="line">    &#125;)</span><br><span class="line">  &#125;,</span><br></pre></td></tr></table></figure>



<h5 id="页面跳转传参为防止对象中存在特殊字符-‘（）8-amp-’等导致解析错误，做双重保障"><a href="#页面跳转传参为防止对象中存在特殊字符-‘（）8-amp-’等导致解析错误，做双重保障" class="headerlink" title="页面跳转传参为防止对象中存在特殊字符 ‘（）8 &amp;’等导致解析错误，做双重保障"></a>页面跳转传参为防止对象中存在特殊字符 ‘（）8 &amp;’等导致解析错误，做双重保障</h5><p>编码：encodeURIComponent(JSON.stringify(Object))</p>
<p>解码：JSON.parse(encodeURIComponent(options.Object))</p>
<h3 id="组件的使用"><a href="#组件的使用" class="headerlink" title="组件的使用"></a>组件的使用</h3><h4 id="滚动组件scroll-view-列表页的加载更多"><a href="#滚动组件scroll-view-列表页的加载更多" class="headerlink" title="滚动组件scroll-view  (列表页的加载更多)"></a>滚动组件scroll-view  (列表页的加载更多)</h4><h5 id="横向滚动使用："><a href="#横向滚动使用：" class="headerlink" title="横向滚动使用："></a>横向滚动使用：</h5><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">scroll-view</span> <span class="attr">scroll-x</span>=<span class="string">&quot;true&quot;</span> <span class="attr">style</span>=<span class="string">&quot; white-space: nowrap; display: flex&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">view</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;logs&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;index&quot;</span> <span class="attr">class</span>=<span class="string">&quot;scroll-list &#123;&#123;current == index  ? &#x27;border-color&#x27;:&#x27;&#x27;&#125;&#125;&quot;</span> <span class="attr">bindtap</span>=<span class="string">&quot;getDetail&quot;</span> <span class="attr">data-item</span>=<span class="string">&quot;&#123;&#123;index&#125;&#125;&quot;</span>&gt;</span>第&#123;&#123;index + 1&#125;&#125;次登陆<span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">scroll-view</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h5 id="竖向滚动使用（实现分页加载）"><a href="#竖向滚动使用（实现分页加载）" class="headerlink" title="竖向滚动使用（实现分页加载）"></a>竖向滚动使用（实现分页加载）</h5><p>滚动组件中flex布局不生效，需要在scroll-view内嵌套一层view标签在这个标签再使用display:flex使用flex布局</p>
<p><strong>常用于设置成垂直布局，进行下拉加载，到达底部触发bindscrolltolower事件，配合防抖进行分页加载更多</strong></p>
<p>wxml: (如果是在scroll-view使用flex：1的话也需要添加height：100%,否则无法下拉滚动)</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;container-wrap&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">scroll-view</span> <span class="attr">scroll-y</span> <span class="attr">class</span>=<span class="string">&quot;content&quot;</span> <span class="attr">bindscrolltolower</span>=<span class="string">&quot;loadmoreDebounce&quot;</span> <span class="attr">wx:if</span>=<span class="string">&quot;&#123;&#123;!noData&#125;&#125;&quot;</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;listData&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;index&quot;</span> <span class="attr">bindtap</span>=<span class="string">&quot;getToDetail&quot;</span> <span class="attr">data-id</span>=<span class="string">&quot;&#123;&#123;item.id&#125;&#125;&quot;</span>&gt;</span> listData遍历出来的每个数据列表的布局 <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">view</span> <span class="attr">wx:if</span>=<span class="string">&quot;&#123;&#123;noMore&#125;&#125;&quot;</span>&gt;</span>没有更多了呦，亲！ <span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">scroll-view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">NoData</span> <span class="attr">wx:else</span>&gt;</span>（此处为没有内容而显示的组件）<span class="tag">&lt;/<span class="name">NoData</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>wxss:</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.container-wrap</span> &#123;</span><br><span class="line">   <span class="attribute">height</span>: <span class="number">100vh</span>;</span><br><span class="line">   <span class="attribute">display</span>: flex;</span><br><span class="line">   <span class="attribute">flex-direction</span>: column;</span><br><span class="line">&#125;</span><br><span class="line"><span class="selector-class">.content</span> &#123;</span><br><span class="line">   <span class="attribute">flex</span>: <span class="number">1</span>;</span><br><span class="line">   <span class="attribute">box-sizing</span>: border-box;</span><br><span class="line">   <span class="attribute">padding</span>: <span class="number">30</span>rpx <span class="number">30</span>rpx;</span><br><span class="line">   <span class="attribute">height</span>: <span class="number">100%</span>;</span><br><span class="line">   <span class="attribute">overflow</span>: hidden;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>js:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123; debounce &#125; <span class="keyword">from</span> <span class="string">&quot;../../utils/basics&quot;</span>;<span class="comment">//引入防抖方法</span></span><br><span class="line">Page(&#123;</span><br><span class="line">  data: &#123;</span><br><span class="line">params: &#123;</span><br><span class="line">         page: <span class="number">1</span>,</span><br><span class="line">         pageSize: <span class="number">10</span>,</span><br><span class="line">&#125;,</span><br><span class="line">&#125;</span><br><span class="line">...</span><br><span class="line">...</span><br><span class="line"><span class="comment">//获取调用接口数据</span></span><br><span class="line"><span class="function"><span class="title">getListData</span>(<span class="params"><span class="built_in">this</span>.data.params</span>)</span>&#123;...&#125;,</span><br><span class="line"><span class="comment">// 防抖加载更多</span></span><br><span class="line">  loadmoreDebounce: debounce(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">      <span class="keyword">if</span> (<span class="built_in">this</span>.data.noMore) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">let</span> page = <span class="built_in">this</span>.data.params.page;</span><br><span class="line">      <span class="built_in">this</span>.setData(&#123;</span><br><span class="line">        <span class="string">&quot;params.page&quot;</span>: page + <span class="number">1</span>,</span><br><span class="line">      &#125;);</span><br><span class="line">      <span class="built_in">this</span>.getListData();</span><br><span class="line">    &#125;, <span class="number">1000</span>),</span><br><span class="line">  &#125;,</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<p>防抖方法—&gt;  basics.js</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/** </span></span><br><span class="line"><span class="comment"> * 防抖函数</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Function&#125;</span> </span>fn </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Number&#125;</span> </span>interval </span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">debounce</span>(<span class="params">fn, interval</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> timer;</span><br><span class="line">  <span class="keyword">var</span> count = <span class="number">0</span>;</span><br><span class="line">  <span class="keyword">var</span> gapTime = interval || <span class="number">1000</span>; <span class="comment">//间隔时间， 如果interval不传，则默认是1000</span></span><br><span class="line">  <span class="keyword">return</span> <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">clearTimeout</span>(timer);</span><br><span class="line">    <span class="keyword">var</span> context = <span class="built_in">this</span>; <span class="comment">//保存此处的arguments，因为setTimeout是全局，arguments不是防抖函数需要的</span></span><br><span class="line">    <span class="keyword">var</span> args = <span class="built_in">arguments</span>;</span><br><span class="line">    <span class="keyword">if</span> (count &gt; <span class="number">0</span>) &#123;</span><br><span class="line">      timer = <span class="built_in">setTimeout</span>(<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">        fn.call(context, ...args);</span><br><span class="line">      &#125;, gapTime);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      count++;</span><br><span class="line">      fn.call(context, ...args);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>上面的防抖为先触发式的防抖，因为运用在下拉刷新加载，我们在第一次触发执行事件的时候就不该延时去调用方法，连续第二次的时候才触发防抖的功能</p>
<p>节流分页加载：</p>
<p>其实这里也可以通过一个loading的字段来进行节流控制，当在触发加载的时候，loading为true，然后在触发加载的方法最上面加上，一个对loading的判断，为true则return，但接口正常返回的时候，loading置为false（当然你也可以用一个节流函数，但是直接用字段的话会更方便简洁）</p>
<h5 id="节流和防抖都是闭包的运用场景，而节流和防抖的运用场景又有哪些呢"><a href="#节流和防抖都是闭包的运用场景，而节流和防抖的运用场景又有哪些呢" class="headerlink" title="节流和防抖都是闭包的运用场景，而节流和防抖的运用场景又有哪些呢"></a>节流和防抖都是闭包的运用场景，而节流和防抖的运用场景又有哪些呢</h5><p>防抖debounce：</p>
<p>1.search搜索联想，用户在不断输入值时，用防抖来节约请求资源。</p>
<p>2.频繁操作点赞和取消点赞，因此需要获取最后一次操作结果并发送给服务器</p>
<p>节流throttle：</p>
<p>1.鼠标不断点击触发，mousedown(单位时间内只触发一次)</p>
<p>2.window触发resize的时候，不断的调整浏览器窗口大小会不断的触发这个事件，用防抖来让其只触发一次</p>
<h4 id="轮播组件swiper"><a href="#轮播组件swiper" class="headerlink" title="轮播组件swiper"></a>轮播组件swiper</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">swiper</span> <span class="attr">class</span>=<span class="string">&quot;swiper-style&quot;</span> <span class="attr">current</span>=<span class="string">&quot;&#123;&#123;current&#125;&#125;&quot;</span> <span class="attr">indicator-dots</span>=<span class="string">&quot;true&quot;</span>  <span class="attr">indicator-active-color</span>=<span class="string">&quot;#000&quot;</span>  <span class="attr">autoplay</span>=<span class="string">&quot;true&quot;</span> <span class="attr">interval</span>=<span class="string">&quot;5000&quot;</span> <span class="attr">duration</span>=<span class="string">&quot;500&quot;</span> <span class="attr">bindchange</span>=<span class="string">&quot;onSlideChangeEnd&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">swiper-item</span> <span class="attr">class</span>=<span class="string">&quot;swiper-style&quot;</span> <span class="attr">wx:for</span>=<span class="string">&quot;&#123;&#123;dataLogs&#125;&#125;&quot;</span> <span class="attr">wx:key</span>=<span class="string">&quot;index&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width: 100%&quot;</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">view</span> <span class="attr">class</span>=<span class="string">&quot;center&quot;</span>&gt;</span>&#123;&#123;item&#125;&#125;<span class="tag">&lt;/<span class="name">view</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">swiper-item</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">swiper</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h5 id="禁止用户手动滑动"><a href="#禁止用户手动滑动" class="headerlink" title="禁止用户手动滑动"></a>禁止用户手动滑动</h5><p>hxml:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">swiper-item</span> <span class="attr">catchtouchmove</span>=<span class="string">&quot;stopTouchMove&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">swiper-item</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>按需禁止：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">swiper-item</span> <span class="attr">catchtouchmove</span>=<span class="string">&quot;&#123;&#123;data.items.length===1? &#x27;forbid&#x27; : &#x27;&#x27;&#125;&#125;&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">swiper-item</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>js:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">stopTouchMove: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123; <span class="keyword">return</span> <span class="literal">false</span>; &#125;</span><br></pre></td></tr></table></figure>



<h4 id="video组件"><a href="#video组件" class="headerlink" title="video组件"></a>video组件</h4><p><strong>video组件默认为inline-block,存在默认边距，若要去除video的css样式属性需要设置display:block</strong></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">video</span>  <span class="attr">bindplay</span>=<span class="string">&quot;play&quot;</span> <span class="attr">bindpause</span>=<span class="string">&quot;pause&quot;</span> <span class="attr">id</span>=<span class="string">&quot;video&quot;</span> <span class="attr">src</span>=<span class="string">&quot;&#123;&#123;item&#125;&#125;&quot;</span> <span class="attr">autoplay</span>=<span class="string">&quot;&#123;&#123;true&#125;&#125;&quot;</span> <span class="attr">show-fullscreen-btn</span>=<span class="string">&quot;&#123;&#123;true&#125;&#125;&quot;</span> <span class="attr">show-play-btn</span>=<span class="string">&quot;&#123;&#123;true&#125;&#125;&quot;</span> <span class="attr">controls</span>=<span class="string">&quot;&#123;&#123;true&#125;&#125;&quot;</span> <span class="attr">enable-progress-gesture</span>=<span class="string">&quot;&#123;&#123;false&#125;&#125;&quot;</span> /&gt;</span></span><br></pre></td></tr></table></figure>

<p>wx.createVideoContext的使用：</p>
<p>wx.createVideoContext(string id, Object this)： wx.createVideoContext(“video”,this)获取id为video的实例，然后调用实例方法pause、play等自定义控制视频的播放和暂停</p>
<p>bindplay、bindpause属性播放和暂停的时候触发</p>
<h4 id="input组件"><a href="#input组件" class="headerlink" title="input组件"></a>input组件</h4><h5 id="左右文字对其上下居中的问题"><a href="#左右文字对其上下居中的问题" class="headerlink" title="左右文字对其上下居中的问题"></a>左右文字对其上下居中的问题</h5><p>需要使用基线中心线对齐，另外设置高度的同时需要覆盖min-height的高度</p>
<h5 id="注意："><a href="#注意：" class="headerlink" title="!!!注意："></a>!!!注意：</h5><p>在ios9.+的版本上，遇到了一个问题。在键盘弹出的时候，快速滚动页面，输入的内容或input提示语会错位。且有时无法恢复到原有位置。当然，<strong>前提是你这个页面是超过一屏需要滚动的时候</strong></p>
<ol>
<li><p>页面可通过样式的滚动（overflow-y: auto）来写，但是不要用 -webkit-overflow-scrolling: touch;</p>
</li>
<li><p>页面用scroll-view,通过变量{sysScroll}来控制（使用过这个方法–可以解决）</p>
</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">onfocus: <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="built_in">this</span>.setData(&#123;<span class="attr">sysScroll</span>: <span class="literal">false</span>&#125;)</span><br><span class="line">  &#125;,</span><br><span class="line">onblur: <span class="function"><span class="keyword">function</span> (<span class="params">e, param, inst</span>) </span>&#123;</span><br><span class="line">    <span class="built_in">this</span>.setData(&#123;<span class="attr">sysScroll</span>: <span class="literal">true</span>&#125;)</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>

<p><strong>input框在页面同时有文本输入的时候，键盘弹起会出现收起后可能会出现抬起页面后没有恢复到原状，解决方案：</strong><br>将input的聚焦键盘弹起自动抬起页面禁用，获取键盘的高度，然后添加下边距（键盘高度），使用滚动页面滚动到指定高度，然后，收起键盘将边距取消</p>
<h3 id="this-setData方法"><a href="#this-setData方法" class="headerlink" title="this.setData方法"></a>this.setData方法</h3><h5 id="setData修改某对象的索引也是需要传字符串"><a href="#setData修改某对象的索引也是需要传字符串" class="headerlink" title="setData修改某对象的索引也是需要传字符串"></a>setData修改某对象的索引也是需要传字符串</h5><p>例如： data:{ name:””}</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">this</span>.setData(&#123;</span><br><span class="line">[<span class="string">&quot;data.name&quot;</span>] :  value</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h5 id="setData中给带下标的数组set数据"><a href="#setData中给带下标的数组set数据" class="headerlink" title="setData中给带下标的数组set数据"></a>setData中给带下标的数组set数据</h5><p>例如： array:[{name:””},{name:””},{name:””}]</p>
<h6 id="1-使用模板字符串"><a href="#1-使用模板字符串" class="headerlink" title="1.使用模板字符串"></a>1.使用模板字符串</h6><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">This.setData(&#123;</span><br><span class="line">[<span class="string">`array<span class="subst">$&#123;index&#125;</span>.id`</span>]:  value</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h6 id="2-使用字符串的方法"><a href="#2-使用字符串的方法" class="headerlink" title="2.使用字符串的方法"></a>2.使用字符串的方法</h6><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">This.setData(&#123;</span><br><span class="line">[<span class="string">&quot;array&quot;</span> + index + <span class="string">&quot;.id&quot;</span>] :  value</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<h3 id="保留上一个页面的数据，解决回退数据丢失"><a href="#保留上一个页面的数据，解决回退数据丢失" class="headerlink" title="保留上一个页面的数据，解决回退数据丢失"></a>保留上一个页面的数据，解决回退数据丢失</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> pages = getCurrentPages(); <span class="comment">//获取当前页面js里面的pages里的所有信息。</span></span><br><span class="line"><span class="keyword">let</span> prevPage = pages[ pages.length - <span class="number">2</span> ];  </span><br><span class="line"> </span><br><span class="line"><span class="comment">//prevPage 是获取上一个页面的js里面的pages的所有信息。 -2 是上一个页面，-3是上上个页面以此类推。</span></span><br><span class="line"> </span><br><span class="line">prevPage.setData(&#123;  <span class="comment">// 将我们想要传递的参数在这里直接setData。上个页面就会执行这里的操作。id为上一个页面的data，把当前页面的数据传值到上一个页面</span></span><br><span class="line">    id:e.currentTarget.dataset.id,</span><br><span class="line">&#125;)</span><br><span class="line"><span class="comment">//上一个页面内执行setData操作，将我们想要的信息保存住。当我们返回去的时候，页面已经处理完毕。</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">//最后就是返回上一个页面。</span></span><br><span class="line">wx.navigateBack(&#123;</span><br><span class="line">    delta: <span class="number">1</span>  <span class="comment">// 返回上一级页面。</span></span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>



<p>获取修改上一个页面的数据</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> pages = getCurrentPages();</span><br><span class="line"><span class="keyword">var</span> Page = pages[pages.length - <span class="number">1</span>]; <span class="comment">//当前页</span></span><br><span class="line"><span class="keyword">var</span> prevPage = pages[pages.length - <span class="number">2</span>]; <span class="comment">//上一个页面</span></span><br><span class="line"><span class="keyword">var</span> info = prevPage.data; <span class="comment">//取上页data里的数据也可以修改</span></span><br><span class="line">prevPage.setData(&#123; 键: 值 &#125;); <span class="comment">//设置数据 </span></span><br></pre></td></tr></table></figure>



<h3 id="小程序生成附带自定义参数（或者跳转url）的二维码"><a href="#小程序生成附带自定义参数（或者跳转url）的二维码" class="headerlink" title="小程序生成附带自定义参数（或者跳转url）的二维码"></a>小程序生成附带自定义参数（或者跳转url）的二维码</h3><p><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/e6021798cd40">https://www.jianshu.com/p/e6021798cd40</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/dillonlfy/weapp-qrcode">https://github.com/dillonlfy/weapp-qrcode</a></p>
<p>其中该代码保存下来的图片比较模糊，与设置生成的画布的大小有关系，所以这里需要修改他的源码，把保存的二维码的尺寸发放大为原来的n倍</p>
<p><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/wps3.jpeg"></p>
<p>(<strong>!!!注意</strong>:不知道为什么小程序的canvas组件在使用hidden隐藏后切换显示下一个的时候出现了闪动的问题，原因（触发重绘，可能二维码重新绘制缓慢），由于canvas的层级比较高，所以需要使用cover组件才能覆盖它)</p>
<p><strong>解决方案：</strong></p>
<p>如果有多个canvas，而且需要切换，使用swiper嵌套，使用轮播的形式切换然后设置切换时间为1毫秒，这样交互体验会好很多（避免了重绘，交互流畅），否则会出现切换缓慢闪动</p>
<h3 id="解决checkbox组件不能直接调整大小，和监听复选框变化"><a href="#解决checkbox组件不能直接调整大小，和监听复选框变化" class="headerlink" title="解决checkbox组件不能直接调整大小，和监听复选框变化"></a>解决checkbox组件不能直接调整大小，和监听复选框变化</h3><p>给checkbox组件添加样式使用 transform: scale(0.5,0.5)   使用方法的方式调整大小</p>
<p>监听复选框的勾选：在checkbox组件外层添加checkbox-group组件添加bindchange方法</p>
<p>hxml:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">checkbox-group</span> <span class="attr">class</span>=<span class="string">&quot;checkbox&quot;</span>  <span class="attr">bindchange</span>=<span class="string">&quot;checkboxChange&quot;</span>&gt;</span></span><br><span class="line">     <span class="tag">&lt;<span class="name">checkbox</span>  <span class="attr">value</span>=<span class="string">&quot;是否阅读&quot;</span>  <span class="attr">checked</span>=<span class="string">&quot;&#123;&#123;checkbox&#125;&#125;&quot;</span>/&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">checkbox-group</span>&gt;</span></span><br></pre></td></tr></table></figure>

<p>js:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">checkboxChange: <span class="function"><span class="keyword">function</span> (<span class="params">e</span>) </span>&#123;</span><br><span class="line"><span class="keyword">if</span> (e.detail.value == <span class="string">&quot;&quot;</span>) &#123;</span><br><span class="line">     <span class="comment">//未勾选</span></span><br><span class="line">      <span class="built_in">this</span>.setData(&#123;</span><br><span class="line">        checkbox: <span class="literal">false</span>,</span><br><span class="line">      &#125;);</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">       <span class="comment">//已勾选</span></span><br><span class="line">      <span class="built_in">this</span>.setData(&#123;</span><br><span class="line">        checkbox: <span class="literal">true</span>,</span><br><span class="line">      &#125;);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure>



<h3 id="我的常用布局及样式"><a href="#我的常用布局及样式" class="headerlink" title="我的常用布局及样式"></a>我的常用布局及样式</h3><h4 id="自定义行数css："><a href="#自定义行数css：" class="headerlink" title="自定义行数css："></a>自定义行数css：</h4><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">white-space</span>: normal;  //正常换行</span><br><span class="line"><span class="attribute">overflow</span>: hidden;</span><br><span class="line"><span class="attribute">text-overflow</span>: ellipsis;</span><br><span class="line"><span class="attribute">display</span>: -webkit-box;</span><br><span class="line">-webkit-line-clamp: <span class="number">2</span>; //两行显示</span><br><span class="line">-webkit-box-orient: vertical;</span><br></pre></td></tr></table></figure>



<h4 id="自适应满屏"><a href="#自适应满屏" class="headerlink" title="自适应满屏"></a>自适应满屏</h4><p>父级标签： height:100vh;   display: flex； flex-direction: column;</p>
<p>自适应子级： flex: 1</p>
<h4 id="flex居中"><a href="#flex居中" class="headerlink" title="flex居中"></a>flex居中</h4><p>flex的上下居中  align-items: center;     左右居中：justify-content:center</p>
<h4 id="两列从左到右水平、均分布局"><a href="#两列从左到右水平、均分布局" class="headerlink" title="两列从左到右水平、均分布局"></a>两列从左到右水平、均分布局</h4><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">display</span>: flex;</span><br><span class="line"><span class="attribute">flex-wrap</span>: wrap;</span><br><span class="line"><span class="attribute">align-content</span>: flex-start;</span><br><span class="line"><span class="attribute">justify-content</span>: space-between;</span><br></pre></td></tr></table></figure>



<h4 id="瀑布流布局横向排序"><a href="#瀑布流布局横向排序" class="headerlink" title="瀑布流布局横向排序"></a>瀑布流布局横向排序</h4><h5 id="两列：（但这个方法需要给父盒子添加高度，如果需要下拉加载，此方法不可行）"><a href="#两列：（但这个方法需要给父盒子添加高度，如果需要下拉加载，此方法不可行）" class="headerlink" title="两列：（但这个方法需要给父盒子添加高度，如果需要下拉加载，此方法不可行）"></a>两列：（但这个方法需要给父盒子添加高度，如果需要下拉加载，此方法不可行）</h5><p>父盒子</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">display</span>: flex;</span><br><span class="line"><span class="attribute">flex-flow</span>: column wrap;</span><br></pre></td></tr></table></figure>



<p>列表—子元素</p>
<p>添加伪元素选择器</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-child</span>(<span class="number">2</span>n) &#123; <span class="attribute">order</span>: <span class="number">2</span>; &#125;</span><br><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-child</span>(<span class="number">2</span>n+<span class="number">1</span>) &#123; <span class="attribute">order</span>: <span class="number">1</span>; &#125;</span><br></pre></td></tr></table></figure>



<p>三列：</p>
<p>列表—子元素</p>
<p>添加伪元素选择器</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-child</span>(<span class="number">3</span>n+<span class="number">1</span>) &#123; <span class="attribute">order</span>: <span class="number">1</span>; &#125;</span><br><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-child</span>(<span class="number">3</span>n+<span class="number">2</span>) &#123; <span class="attribute">order</span>: <span class="number">2</span>; &#125;</span><br><span class="line"><span class="selector-class">.item</span><span class="selector-pseudo">:nth-child</span>(<span class="number">3</span>n)   &#123; <span class="attribute">order</span>: <span class="number">3</span>; &#125;</span><br></pre></td></tr></table></figure>



<h5 id="display-flex-flex-direction-column-数据分组-（下拉加载可行）"><a href="#display-flex-flex-direction-column-数据分组-（下拉加载可行）" class="headerlink" title="display: flex; flex-direction: column;数据分组 （下拉加载可行）"></a>display: flex; flex-direction: column;数据分组 （下拉加载可行）</h5><p>但要这样实现多列好像需要设置高度，这里确定这个高度比较难，使用flex的话考虑使用数据分组，两列的话奇数偶数分别存储，放到对应列渲染，但需要实现真正的瀑布流还需要计算高度，哪边低优先排到哪一边（目前在小程序上使用过这个方法，但没计算高度，无限流，如果小程序上使用一组计算高度，一组真正的显示，需要每次加载计算两列的高度再进行排分，这样需要花费的计算时间，可能会比较大。）</p>
<p>(这里如果后端没有返回高度的话，可以自定义一组高度的数据，然后通过随机函数给各个元素设置高度，模拟瀑布流，然后图片取中自适应即可)</p>
<p>css： </p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">display</span>:flex; </span><br><span class="line"><span class="attribute">flex-flow</span>: column wrap;</span><br></pre></td></tr></table></figure>

<p>然后两列都使用这个类，父盒子可以使用display: flex;布局然后两列加flex：1在第一列加margin边距即可</p>
<h5 id="column（下拉加载可行，当排序时从上往下排序）"><a href="#column（下拉加载可行，当排序时从上往下排序）" class="headerlink" title="column（下拉加载可行，当排序时从上往下排序）"></a>column（下拉加载可行，当排序时从上往下排序）</h5><p>使用<strong>column也可以实现多列</strong>，这个的话虽然不用定高度，但最大的缺点是<strong>排序只能是从上往下</strong></p>
<p>父盒子：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="attribute">column-count</span>: 设置共有几列</span><br><span class="line">column-width: 设置每列宽度，列数由总宽度与每列宽度计算得出</span><br><span class="line">column-gap: 设置列与列之间的间距</span><br></pre></td></tr></table></figure>

<p>如果瀑布流的每个元素的高度不定使用自适应的方式，那么如果盒子没有预先设置高度或者使用占位符，在加载的时候会出现抖动的现象</p>
<h3 id="使用wxs进行时间戳格式化（类似于vue的fillter函数）"><a href="#使用wxs进行时间戳格式化（类似于vue的fillter函数）" class="headerlink" title="使用wxs进行时间戳格式化（类似于vue的fillter函数）"></a>使用wxs进行时间戳格式化（类似于vue的fillter函数）</h3><p>wxml:</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">view</span>&gt;</span>&#123;&#123;dateUtil.dateFormat(time,&#x27;YYYY-MM-dd hh:mm:ss&#x27;)&#125;&#125;<span class="tag">&lt;<span class="name">view</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">wxs</span> <span class="attr">module</span>=<span class="string">&#x27;dateUtil&#x27;</span> <span class="attr">src</span>=<span class="string">&#x27;../util/util.wxs&#x27;</span>&gt;</span><span class="tag">&lt;/<span class="name">wxs</span>&gt;</span></span><br></pre></td></tr></table></figure>



<p>util.wxs:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param </span>n </span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> formatNumber = <span class="function"><span class="keyword">function</span> (<span class="params">n</span>) </span>&#123;</span><br><span class="line">  n = n.toString();</span><br><span class="line">  <span class="keyword">return</span> n[<span class="number">1</span>] ? n : <span class="string">&quot;0&quot;</span> + n;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">var</span> regYear = getRegExp(<span class="string">&quot;(y+)&quot;</span>, <span class="string">&quot;i&quot;</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Number&#125;</span> </span>timestamp 时间戳</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;String&#125;</span> </span>format 格式 </span></span><br><span class="line"><span class="comment"> * <span class="doctag">@param <span class="type">&#123;Boolean&#125;</span> </span>flag  默认传入时间戳精确到毫秒  13位的时间戳精确到毫秒,如果传入的时间戳为10位精确到秒flag需为true需乘1000</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="keyword">var</span> dateFormat = <span class="function"><span class="keyword">function</span> (<span class="params">timestamp, format, flag</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> ms = flag === <span class="literal">true</span> ? <span class="number">1000</span> : <span class="number">1</span></span><br><span class="line">  <span class="keyword">if</span> (!format) &#123;</span><br><span class="line">    format = <span class="string">&quot;yyyy-MM-dd hh:mm:ss&quot;</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  timestamp = <span class="built_in">parseInt</span>(timestamp) * ms;</span><br><span class="line">  <span class="keyword">var</span> realDate = getDate(timestamp);</span><br><span class="line">  <span class="function"><span class="keyword">function</span> <span class="title">timeFormat</span>(<span class="params">num</span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> num &lt; <span class="number">10</span> ? <span class="string">&quot;0&quot;</span> + num : num;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">var</span> date = [</span><br><span class="line">    [<span class="string">&quot;M+&quot;</span>, timeFormat(realDate.getMonth() + <span class="number">1</span>)],</span><br><span class="line">    [<span class="string">&quot;d+&quot;</span>, timeFormat(realDate.getDate())],</span><br><span class="line">    [<span class="string">&quot;h+&quot;</span>, timeFormat(realDate.getHours())],</span><br><span class="line">    [<span class="string">&quot;m+&quot;</span>, timeFormat(realDate.getMinutes())],</span><br><span class="line">    [<span class="string">&quot;s+&quot;</span>, timeFormat(realDate.getSeconds())],</span><br><span class="line">    [<span class="string">&quot;q+&quot;</span>, <span class="built_in">Math</span>.floor((realDate.getMonth() + <span class="number">3</span>) / <span class="number">3</span>)],</span><br><span class="line">    [<span class="string">&quot;S+&quot;</span>, realDate.getMilliseconds()],</span><br><span class="line">  ];</span><br><span class="line">  <span class="keyword">var</span> reg1 = regYear.exec(format);</span><br><span class="line">  <span class="comment">// console.log(reg1[0]);</span></span><br><span class="line">  <span class="keyword">if</span> (reg1) &#123;</span><br><span class="line">    format = format.replace(</span><br><span class="line">      reg1[<span class="number">1</span>],</span><br><span class="line">      (realDate.getFullYear() + <span class="string">&quot;&quot;</span>).substring(<span class="number">4</span> - reg1[<span class="number">1</span>].length)</span><br><span class="line">    );</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>; i &lt; date.length; i++) &#123;</span><br><span class="line">    <span class="keyword">var</span> k = date[i][<span class="number">0</span>];</span><br><span class="line">    <span class="keyword">var</span> v = date[i][<span class="number">1</span>];</span><br><span class="line"></span><br><span class="line">    <span class="keyword">var</span> reg2 = getRegExp(<span class="string">&quot;(&quot;</span> + k + <span class="string">&quot;)&quot;</span>).exec(format);</span><br><span class="line">    <span class="keyword">if</span> (reg2) &#123;</span><br><span class="line">      format = format.replace(</span><br><span class="line">        reg2[<span class="number">1</span>],</span><br><span class="line">        reg2[<span class="number">1</span>].length == <span class="number">1</span> ? v : (<span class="string">&quot;00&quot;</span> + v).substring((<span class="string">&quot;&quot;</span> + v).length)</span><br><span class="line">      );</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> format;</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="built_in">module</span>.exports = &#123;</span><br><span class="line">  dateFormat: dateFormat,</span><br><span class="line">&#125;;</span><br><span class="line"></span><br></pre></td></tr></table></figure>



<h3 id="开屏动画，出现抖动的情况"><a href="#开屏动画，出现抖动的情况" class="headerlink" title="开屏动画，出现抖动的情况"></a>开屏动画，出现抖动的情况</h3><p><strong>原因</strong>：是因为没有启动硬件加速的原因<br><strong>解决方案</strong>:启动硬件加速，方式有：translate3D，translateZ，transform</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-class">.css</span>&#123;</span><br><span class="line">-webkit-<span class="attribute">transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">-moz-<span class="attribute">transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">-ms-<span class="attribute">transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line"><span class="attribute">transform</span>: <span class="built_in">translate3d</span>(<span class="number">0</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="重写路由跳转方法，添加回调cb"><a href="#重写路由跳转方法，添加回调cb" class="headerlink" title="重写路由跳转方法，添加回调cb"></a>重写路由跳转方法，添加回调cb</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> router = <span class="function"><span class="keyword">function</span> (<span class="params">cb</span>) </span>&#123;</span><br><span class="line">    init()</span><br><span class="line">    <span class="keyword">let</span> obj = &#123;</span><br><span class="line">        navigateTo: wx.navigateTo,</span><br><span class="line">        switchTab: wx.switchTab,</span><br><span class="line">        reLaunch: wx.reLaunch,</span><br><span class="line">        redirectTo: wx.redirectTo,</span><br><span class="line">        navigateBack: wx.navigateBack</span><br><span class="line">         &#125;</span><br><span class="line">    <span class="keyword">for</span>(<span class="keyword">let</span> key <span class="keyword">in</span> obj) &#123;</span><br><span class="line">        wx[key] = <span class="keyword">async</span> <span class="function"><span class="keyword">function</span> (<span class="params">params</span>) </span>&#123;</span><br><span class="line">            <span class="keyword">let</span> fun = obj[key]</span><br><span class="line">            <span class="keyword">await</span> fun(params)</span><br><span class="line">            <span class="keyword">let</span> url =  <span class="keyword">await</span> getCurrentPages()</span><br><span class="line">            <span class="keyword">await</span> cb(&#123;</span><br><span class="line">                url,</span><br><span class="line">                routerMethod:key,</span><br><span class="line">                to: params</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125; </span><br><span class="line"><span class="comment">// 重新设置wx的路由跳转方法</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">init</span> (<span class="params"></span>)</span>&#123;</span><br><span class="line">    <span class="keyword">let</span> obj = &#123;</span><br><span class="line">        navigateTo: wx.navigateTo,</span><br><span class="line">        switchTab: wx.switchTab,</span><br><span class="line">        reLaunch: wx.reLaunch,</span><br><span class="line">        redirectTo: wx.redirectTo,</span><br><span class="line">        navigateBack: wx.navigateBack</span><br><span class="line">      &#125;</span><br><span class="line">      <span class="keyword">for</span>(<span class="keyword">let</span> key <span class="keyword">in</span> obj) &#123;</span><br><span class="line">        <span class="built_in">Object</span>.defineProperty(wx, key,&#123;</span><br><span class="line">          get: <span class="function"><span class="keyword">function</span> (<span class="params"></span>)</span>&#123;</span><br><span class="line">            <span class="keyword">return</span> obj[key]</span><br><span class="line">          &#125;,</span><br><span class="line">          set: <span class="function"><span class="keyword">function</span> (<span class="params">val</span>)</span>&#123;</span><br><span class="line">            obj[key] = val</span><br><span class="line">          &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">      &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">module</span>.exports = router</span><br></pre></td></tr></table></figure>





<h3 id="小程序版本发布流程："><a href="#小程序版本发布流程：" class="headerlink" title="小程序版本发布流程："></a>小程序版本发布流程：</h3><ol>
<li><p>先在小程序开发者工具点击上传，上传本地代码，填上相关版本更新的信息，（注意版本号不能和以前的相同）</p>
</li>
<li><p>先登陆微信第三方登陆平台</p>
<p><a target="_blank" rel="noopener" href="https://open.weixin.qq.com/cgi-bin/index?t=home/">https://open.weixin.qq.com/cgi-bin/index?t=home/</a></p>
<p>管理中心 —-》 第三方平台 —-》选择对应的小程序—-点击详情 —-》开发配置 —-》小程序模板库—-草稿箱（这里可以看到你刚上传的版本相关信息）—–》添加到模板库</p>
<p>此时在小程序模板库就能看到你的刚在草稿箱添加的模板了</p>
</li>
<li><p>登陆微信公众号平台</p>
<p><a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/cgi-bin/loginpage?url=/cgi-bin/home?t=home/index&token=732218211&lang=zh_CN">https://mp.weixin.qq.com/cgi-bin/loginpage?url=%2Fcgi-bin%2Fhome%3Ft%3Dhome%2Findex%26token%3D732218211%26lang%3Dzh_CN</a></p>
<p>​    设置 —-》第三方设置 —》看到对应的小程序—点击停止授权</p>
</li>
<li><p>然后登陆运营平台，小程序托管—点击小程序授权（此处需要管理员扫码）</p>
</li>
</ol>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">mozihao</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://mo_zi_hao.gitee.io/blog/posts/35506/">https://mo_zi_hao.gitee.io/blog/posts/35506/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://mo_zi_hao.gitee.io/blog" target="_blank">mozihao</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/blog/tags/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F/">微信小程序</a></div><div class="post_share"><div class="social-share" data-image="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/1234.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/blog/posts/449/"><img class="prev-cover" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/26&amp;gp=0.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">前端js基础</div></div></a></div><div class="next-post pull-right"><a href="/blog/posts/15318/"><img class="next-cover" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/745.jpg" onerror="onerror=null;src='/blog/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">webpack</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC008.jpg" onerror="this.onerror=null;this.src='/blog/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">mozihao</div><div class="author-info__description">if you risk nothing,then you risk anthing</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/blog/archives/"><div class="headline">文章</div><div class="length-num">24</div></a></div><div class="card-info-data-item is-center"><a href="/blog/tags/"><div class="headline">标签</div><div class="length-num">16</div></a></div><div class="card-info-data-item is-center"><a href="/blog/categories/"><div class="headline">分类</div><div class="length-num">11</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/mo_zi_hao"><i class="iconfont icon-gitee-fill-round"></i><span>我的Gitee</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://gitee.com/mo_zi_hao" target="_blank" title="Gitee"><i class="fab iconfont icon-gitee-fill-round"></i></a><a class="social-icon" href="https://github.com/mmCrazy" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/xiaomohhh?spm=1001.2101.3001.5343" target="_blank" title="CSDN"><i class="fab iconfont icon-csdn"></i></a><a class="social-icon" href="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/qrcode_for_gh_d35478eda980_430.jpg" target="_blank" title="公众号"><i class="fab iconfont icon-weixingongzhonghao"></i></a><a class="social-icon" href="mailto:747304031@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">如文章中有哪些错漏，欢迎各位前端的大佬与我交流并指正，谢谢!!</br>邮箱：747304031@qq.com</br>公众号：一起写前端bug</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">1.</span> <span class="toc-text">页面的生命周期</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">2.</span> <span class="toc-text">组件的生命周期</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#hidden%E6%8E%A7%E5%88%B6%E7%BB%84%E4%BB%B6%E4%B8%8D%E7%94%9F%E6%95%88"><span class="toc-number">3.</span> <span class="toc-text">hidden控制组件不生效</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#navigateTo"><span class="toc-number">4.</span> <span class="toc-text">navigateTo</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B8%A6%E5%8F%82%E4%BC%A0%E5%80%BC%E8%8E%B7%E5%8F%96%E5%B1%9E%E6%80%A7%E5%80%BC"><span class="toc-number">5.</span> <span class="toc-text">带参传值获取属性值</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%88%B6%E5%AD%90%E7%BB%84%E4%BB%B6%E4%B9%8B%E9%97%B4%E7%9A%84%E4%BC%A0%E5%80%BC"><span class="toc-number">6.</span> <span class="toc-text">父子组件之间的传值</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%88%B6%E4%BC%A0%E5%AD%90"><span class="toc-number">6.1.</span> <span class="toc-text">父传子</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AD%90%E4%BC%A0%E7%88%B6"><span class="toc-number">6.2.</span> <span class="toc-text">子传父</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%91%E7%BB%91%E5%AE%9A%E7%9A%84%E6%96%B9%E6%B3%95%E4%BC%A0%E5%8F%82"><span class="toc-number">7.</span> <span class="toc-text">向绑定的方法传参</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8F%98%E9%87%8F%E2%80%93%E5%8F%82%E6%95%B0"><span class="toc-number">7.1.</span> <span class="toc-text">获取自定义变量–参数:</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC-%E4%BC%A0%E5%8F%82%EF%BC%88wx-navgateTo%E4%B8%8D%E8%83%BD%E8%B7%B3%E8%BD%AC%E5%88%B0tabber%E9%A1%B5%E9%9D%A2%EF%BC%89"><span class="toc-number">7.2.</span> <span class="toc-text">页面跳转+传参（wx.navgateTo不能跳转到tabber页面）:</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%BA%E9%81%BF%E5%85%8D%E5%B8%A6%E5%8F%82%E7%9A%84%E5%8F%82%E6%95%B0%E4%B8%AD%E5%AD%98%E5%9C%A8-%EF%BC%9F-%E4%BC%9A%E5%87%BA%E7%8E%B0%E5%8F%82%E6%95%B0%E4%B8%A2%E5%A4%B1%E7%9A%84%E6%83%85%E5%86%B5"><span class="toc-number">7.2.1.</span> <span class="toc-text">为避免带参的参数中存在 ？ ,会出现参数丢失的情况:</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E8%B7%B3%E8%BD%AC%E4%BC%A0%E5%8F%82%E4%B8%BA%E9%98%B2%E6%AD%A2%E5%AF%B9%E8%B1%A1%E4%B8%AD%E5%AD%98%E5%9C%A8%E7%89%B9%E6%AE%8A%E5%AD%97%E7%AC%A6-%E2%80%98%EF%BC%88%EF%BC%898-amp-%E2%80%99%E7%AD%89%E5%AF%BC%E8%87%B4%E8%A7%A3%E6%9E%90%E9%94%99%E8%AF%AF%EF%BC%8C%E5%81%9A%E5%8F%8C%E9%87%8D%E4%BF%9D%E9%9A%9C"><span class="toc-number">7.2.2.</span> <span class="toc-text">页面跳转传参为防止对象中存在特殊字符 ‘（）8 &amp;’等导致解析错误，做双重保障</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="toc-number">8.</span> <span class="toc-text">组件的使用</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%BB%9A%E5%8A%A8%E7%BB%84%E4%BB%B6scroll-view-%E5%88%97%E8%A1%A8%E9%A1%B5%E7%9A%84%E5%8A%A0%E8%BD%BD%E6%9B%B4%E5%A4%9A"><span class="toc-number">8.1.</span> <span class="toc-text">滚动组件scroll-view  (列表页的加载更多)</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%A8%AA%E5%90%91%E6%BB%9A%E5%8A%A8%E4%BD%BF%E7%94%A8%EF%BC%9A"><span class="toc-number">8.1.1.</span> <span class="toc-text">横向滚动使用：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%AB%96%E5%90%91%E6%BB%9A%E5%8A%A8%E4%BD%BF%E7%94%A8%EF%BC%88%E5%AE%9E%E7%8E%B0%E5%88%86%E9%A1%B5%E5%8A%A0%E8%BD%BD%EF%BC%89"><span class="toc-number">8.1.2.</span> <span class="toc-text">竖向滚动使用（实现分页加载）</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%8A%82%E6%B5%81%E5%92%8C%E9%98%B2%E6%8A%96%E9%83%BD%E6%98%AF%E9%97%AD%E5%8C%85%E7%9A%84%E8%BF%90%E7%94%A8%E5%9C%BA%E6%99%AF%EF%BC%8C%E8%80%8C%E8%8A%82%E6%B5%81%E5%92%8C%E9%98%B2%E6%8A%96%E7%9A%84%E8%BF%90%E7%94%A8%E5%9C%BA%E6%99%AF%E5%8F%88%E6%9C%89%E5%93%AA%E4%BA%9B%E5%91%A2"><span class="toc-number">8.1.3.</span> <span class="toc-text">节流和防抖都是闭包的运用场景，而节流和防抖的运用场景又有哪些呢</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%BD%AE%E6%92%AD%E7%BB%84%E4%BB%B6swiper"><span class="toc-number">8.2.</span> <span class="toc-text">轮播组件swiper</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%A6%81%E6%AD%A2%E7%94%A8%E6%88%B7%E6%89%8B%E5%8A%A8%E6%BB%91%E5%8A%A8"><span class="toc-number">8.2.1.</span> <span class="toc-text">禁止用户手动滑动</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#video%E7%BB%84%E4%BB%B6"><span class="toc-number">8.3.</span> <span class="toc-text">video组件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#input%E7%BB%84%E4%BB%B6"><span class="toc-number">8.4.</span> <span class="toc-text">input组件</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%B7%A6%E5%8F%B3%E6%96%87%E5%AD%97%E5%AF%B9%E5%85%B6%E4%B8%8A%E4%B8%8B%E5%B1%85%E4%B8%AD%E7%9A%84%E9%97%AE%E9%A2%98"><span class="toc-number">8.4.1.</span> <span class="toc-text">左右文字对其上下居中的问题</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%B3%A8%E6%84%8F%EF%BC%9A"><span class="toc-number">8.4.2.</span> <span class="toc-text">!!!注意：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#this-setData%E6%96%B9%E6%B3%95"><span class="toc-number">9.</span> <span class="toc-text">this.setData方法</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#setData%E4%BF%AE%E6%94%B9%E6%9F%90%E5%AF%B9%E8%B1%A1%E7%9A%84%E7%B4%A2%E5%BC%95%E4%B9%9F%E6%98%AF%E9%9C%80%E8%A6%81%E4%BC%A0%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">9.0.1.</span> <span class="toc-text">setData修改某对象的索引也是需要传字符串</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#setData%E4%B8%AD%E7%BB%99%E5%B8%A6%E4%B8%8B%E6%A0%87%E7%9A%84%E6%95%B0%E7%BB%84set%E6%95%B0%E6%8D%AE"><span class="toc-number">9.0.2.</span> <span class="toc-text">setData中给带下标的数组set数据</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#1-%E4%BD%BF%E7%94%A8%E6%A8%A1%E6%9D%BF%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">9.0.2.1.</span> <span class="toc-text">1.使用模板字符串</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#2-%E4%BD%BF%E7%94%A8%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9A%84%E6%96%B9%E6%B3%95"><span class="toc-number">9.0.2.2.</span> <span class="toc-text">2.使用字符串的方法</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BF%9D%E7%95%99%E4%B8%8A%E4%B8%80%E4%B8%AA%E9%A1%B5%E9%9D%A2%E7%9A%84%E6%95%B0%E6%8D%AE%EF%BC%8C%E8%A7%A3%E5%86%B3%E5%9B%9E%E9%80%80%E6%95%B0%E6%8D%AE%E4%B8%A2%E5%A4%B1"><span class="toc-number">10.</span> <span class="toc-text">保留上一个页面的数据，解决回退数据丢失</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%94%9F%E6%88%90%E9%99%84%E5%B8%A6%E8%87%AA%E5%AE%9A%E4%B9%89%E5%8F%82%E6%95%B0%EF%BC%88%E6%88%96%E8%80%85%E8%B7%B3%E8%BD%ACurl%EF%BC%89%E7%9A%84%E4%BA%8C%E7%BB%B4%E7%A0%81"><span class="toc-number">11.</span> <span class="toc-text">小程序生成附带自定义参数（或者跳转url）的二维码</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%A3%E5%86%B3checkbox%E7%BB%84%E4%BB%B6%E4%B8%8D%E8%83%BD%E7%9B%B4%E6%8E%A5%E8%B0%83%E6%95%B4%E5%A4%A7%E5%B0%8F%EF%BC%8C%E5%92%8C%E7%9B%91%E5%90%AC%E5%A4%8D%E9%80%89%E6%A1%86%E5%8F%98%E5%8C%96"><span class="toc-number">12.</span> <span class="toc-text">解决checkbox组件不能直接调整大小，和监听复选框变化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%88%91%E7%9A%84%E5%B8%B8%E7%94%A8%E5%B8%83%E5%B1%80%E5%8F%8A%E6%A0%B7%E5%BC%8F"><span class="toc-number">13.</span> <span class="toc-text">我的常用布局及样式</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E8%A1%8C%E6%95%B0css%EF%BC%9A"><span class="toc-number">13.1.</span> <span class="toc-text">自定义行数css：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%87%AA%E9%80%82%E5%BA%94%E6%BB%A1%E5%B1%8F"><span class="toc-number">13.2.</span> <span class="toc-text">自适应满屏</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#flex%E5%B1%85%E4%B8%AD"><span class="toc-number">13.3.</span> <span class="toc-text">flex居中</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%A4%E5%88%97%E4%BB%8E%E5%B7%A6%E5%88%B0%E5%8F%B3%E6%B0%B4%E5%B9%B3%E3%80%81%E5%9D%87%E5%88%86%E5%B8%83%E5%B1%80"><span class="toc-number">13.4.</span> <span class="toc-text">两列从左到右水平、均分布局</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%80%91%E5%B8%83%E6%B5%81%E5%B8%83%E5%B1%80%E6%A8%AA%E5%90%91%E6%8E%92%E5%BA%8F"><span class="toc-number">13.5.</span> <span class="toc-text">瀑布流布局横向排序</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%A4%E5%88%97%EF%BC%9A%EF%BC%88%E4%BD%86%E8%BF%99%E4%B8%AA%E6%96%B9%E6%B3%95%E9%9C%80%E8%A6%81%E7%BB%99%E7%88%B6%E7%9B%92%E5%AD%90%E6%B7%BB%E5%8A%A0%E9%AB%98%E5%BA%A6%EF%BC%8C%E5%A6%82%E6%9E%9C%E9%9C%80%E8%A6%81%E4%B8%8B%E6%8B%89%E5%8A%A0%E8%BD%BD%EF%BC%8C%E6%AD%A4%E6%96%B9%E6%B3%95%E4%B8%8D%E5%8F%AF%E8%A1%8C%EF%BC%89"><span class="toc-number">13.5.1.</span> <span class="toc-text">两列：（但这个方法需要给父盒子添加高度，如果需要下拉加载，此方法不可行）</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#display-flex-flex-direction-column-%E6%95%B0%E6%8D%AE%E5%88%86%E7%BB%84-%EF%BC%88%E4%B8%8B%E6%8B%89%E5%8A%A0%E8%BD%BD%E5%8F%AF%E8%A1%8C%EF%BC%89"><span class="toc-number">13.5.2.</span> <span class="toc-text">display: flex; flex-direction: column;数据分组 （下拉加载可行）</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#column%EF%BC%88%E4%B8%8B%E6%8B%89%E5%8A%A0%E8%BD%BD%E5%8F%AF%E8%A1%8C%EF%BC%8C%E5%BD%93%E6%8E%92%E5%BA%8F%E6%97%B6%E4%BB%8E%E4%B8%8A%E5%BE%80%E4%B8%8B%E6%8E%92%E5%BA%8F%EF%BC%89"><span class="toc-number">13.5.3.</span> <span class="toc-text">column（下拉加载可行，当排序时从上往下排序）</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8wxs%E8%BF%9B%E8%A1%8C%E6%97%B6%E9%97%B4%E6%88%B3%E6%A0%BC%E5%BC%8F%E5%8C%96%EF%BC%88%E7%B1%BB%E4%BC%BC%E4%BA%8Evue%E7%9A%84fillter%E5%87%BD%E6%95%B0%EF%BC%89"><span class="toc-number">14.</span> <span class="toc-text">使用wxs进行时间戳格式化（类似于vue的fillter函数）</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%80%E5%B1%8F%E5%8A%A8%E7%94%BB%EF%BC%8C%E5%87%BA%E7%8E%B0%E6%8A%96%E5%8A%A8%E7%9A%84%E6%83%85%E5%86%B5"><span class="toc-number">15.</span> <span class="toc-text">开屏动画，出现抖动的情况</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%87%8D%E5%86%99%E8%B7%AF%E7%94%B1%E8%B7%B3%E8%BD%AC%E6%96%B9%E6%B3%95%EF%BC%8C%E6%B7%BB%E5%8A%A0%E5%9B%9E%E8%B0%83cb"><span class="toc-number">16.</span> <span class="toc-text">重写路由跳转方法，添加回调cb</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%89%88%E6%9C%AC%E5%8F%91%E5%B8%83%E6%B5%81%E7%A8%8B%EF%BC%9A"><span class="toc-number">17.</span> <span class="toc-text">小程序版本发布流程：</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/1/" title="无题"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="无题"/></a><div class="content"><a class="title" href="/blog/posts/1/" title="无题">无题</a><time datetime="2022-06-05T05:20:17.974Z" title="发表于 2022-06-05 13:20:17">2022-06-05</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/36549/" title="编写可维护的JavaScript (代码习惯)"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/%E6%B5%B7%E8%B4%BC4.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="编写可维护的JavaScript (代码习惯)"/></a><div class="content"><a class="title" href="/blog/posts/36549/" title="编写可维护的JavaScript (代码习惯)">编写可维护的JavaScript (代码习惯)</a><time datetime="2022-03-19T03:12:42.624Z" title="发表于 2022-03-19 11:12:42">2022-03-19</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/23125/" title="gitlab-cicd"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/745.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="gitlab-cicd"/></a><div class="content"><a class="title" href="/blog/posts/23125/" title="gitlab-cicd">gitlab-cicd</a><time datetime="2021-12-20T14:00:59.661Z" title="发表于 2021-12-20 22:00:59">2021-12-20</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/449/" title="前端js基础"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/26&amp;gp=0.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="前端js基础"/></a><div class="content"><a class="title" href="/blog/posts/449/" title="前端js基础">前端js基础</a><time datetime="2021-08-29T15:22:14.600Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/blog/posts/35506/" title="微信小程序"><img src="https://gitee.com/mo_zi_hao/picsBed/raw/master/image/1234.jpg" onerror="this.onerror=null;this.src='/blog/img/404.jpg'" alt="微信小程序"/></a><div class="content"><a class="title" href="/blog/posts/35506/" title="微信小程序">微信小程序</a><time datetime="2021-08-29T15:22:14.600Z" title="发表于 2021-08-29 23:22:14">2021-08-29</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By mozihao</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/blog/js/utils.js"></script><script src="/blog/js/main.js"></script><script src="/blog/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="/blog/js/search/local-search.js"></script><div class="js-pjax"></div><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/gh/metowolf/MetingJS@1.2/dist/Meting.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>